import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';

class WidgetUtils {
  /// Widget渲染监听，监听widget宽高变化,callback返回宽高等参数.
  static void asyncPrepare(
      BuildContext context, bool isOnce, ValueChanged<Rect> onCallBack) {
    WidgetUtil widgetUtil = new WidgetUtil();
    widgetUtil.asyncPrepare(context, isOnce, onCallBack);
  }

  /// 获取widget Rect
  static Rect getWidgetBounds(BuildContext context) {
    return WidgetUtil.getWidgetBounds(context);
  }

  /// 获取widget Offset,获取widget在屏幕上的坐标,widget必须渲染完成
  static Offset getWidgetLocalToGlobal(BuildContext context) {
    return WidgetUtil.getWidgetLocalToGlobal(context);
  }

  /// 获取CachedNetworkImage下的图片尺寸
  static Rect getImageWHFromImage(Image image) {
    Rect rect = WidgetUtil.getImageWH(image: image) as Rect;
    return rect;
  }

  /// 获取CachedNetworkImage下的图片尺寸
  static Rect getImageWHFromLocalUrl(String localUrl) {
    Rect rect = WidgetUtil.getImageWH(localUrl: localUrl) as Rect;
    return rect;
  }

  /// 获取CachedNetworkImage下的图片尺寸
  static Rect getImageWHFromUrl(String url) {
    Rect rect = WidgetUtil.getImageWH(url: url) as Rect;
    return rect;
  }
}
